<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%--
    Document   : blank
    Created on : 19.11.2008, 15:33:27
    Author     : Cyclone
--%>

<%@page import="java.util.Map" %>
<%@page import="ru.miit.elearning.hibernate.dto.CurriculumLevel" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">


<body>

    <script src="js/courses.js" type="text/javascript"></script>

    <%@include file="systemMessage.jsp" %>

    <!-- <div id="box"> -->
    <div id="box" style="overflow: auto;" class="rounded">
        <div id="rightnow" style="border: none;" class="rounded-top">
            <h3 class="reallynow rounded-top">
                Курсы
                <%--<c:if test="${sessionScope.roles.admin || sessionScope.role.tutor}">--%>
                <c:if test='<%= request.isUserInRole("admin") || request.isUserInRole("tutor")%>'>
                    <a class="add_page" onclick="$('div#newFormDiv').show('slow', function(){window.location = '#addCourse'});">Добавить курс</a>
                </c:if>
                <br/>
            </h3>
        </div>

        <c:choose>
            <c:when test="${!empty courseList}">
                <form id="form" style="padding: 0px;">
                    <table id="courseTable" class="datatable" align="left">
                        <thead>
                            <tr>
                                <c:if test='<%= request.isUserInRole("admin") || request.isUserInRole("tutor")%>'>
                                    <th width="27"><a href="?sort=id">ID<c:if test="${param.sort == 'id'}"><img src="img/icons/arrow_down_mini.gif" class="arrow_img" alt="V" width="16" height="16" align="absmiddle" /></c:if></a></th>
                                        </c:if>
                                <th width="29"><a href="?sort=numeral">№<c:if test="${param.sort == 'numeral'}"><img src="img/icons/arrow_down_mini.gif" class="arrow_img" alt="V" width="16" height="16" align="absmiddle" /></c:if></a></th>
                                <th><a href="?sort=title">Название курса<c:if test="${param.sort == 'title'}"><img src="img/icons/arrow_down_mini.gif" width="16" height="16" align="absmiddle" /></c:if></a></th>
                                <th width="100"><a href="?sort=curriculumLevel">Направление<c:if test="${empty param.sort || param.sort == 'curriculumLevel'}"><img src="img/icons/arrow_down_mini.gif" alt="V" width="16" height="16" align="absmiddle" /></c:if></a></th>
                                <th width="20" title="Количество студентов, изучающих курс">С</th>
                                <th width="60">Описание</th>
                                <th>Операции</th>
                            </tr>
                        </thead>
                        <tbody>
                            <c:forEach var="course" items="${courseList}">

                                <tr>
                                    <c:if test='<%= request.isUserInRole("admin") || request.isUserInRole("tutor")%>'>
                                        <td class="a-center">${course.id}</td>
                                    </c:if>
                                    <td class="a-center">${course.numeral}</td>
                                    <td><a href="Course?id=${course.id}" title="Просмотреть описание курса">${course.title}</a></td>
                                    <td>${course.curriculumLevel.title}</td>
                                    <td class="a-center">
                                        <input type="button" value="#" title="Запросить количество студентов" style="width: 100%; margin: 0px; padding-left: 1px; padding-right: 1px; cursor: help;" onclick="getStudentCount(event, ${course.id});" />
                                    </td>
                                    <td><input type="button" value="Просмотреть" style="width: 100%; margin: 0px; cursor: help" onclick="showDescription(${course.id});"/></td>
                                    <td  style="padding: 0px;">
                                        <select id="actionSelect" onchange="actionSelectChange(event, ${course.id})" style="width: 60px; margin: 0px;">
                                            <option value="-1" selected="selected">...</option>
                                            <optgroup label="Студенты">
                                                <option value="0" class="signOn">Списки</option>
                                            </optgroup>
                                            <optgroup label="Тьюторы">
                                                <c:choose><c:when test='<%= request.isUserInRole("admin")%>'>
                                                        <option value="2" class="signOn">Назначение</option>
                                                    </c:when><c:otherwise>
                                                        <option value="2" class="signOn">Списки</option>
                                                    </c:otherwise></c:choose>
                                                </optgroup>
                                                <optgroup label="Общие">
                                                    <option value="4">О курсе</option>
                                                <c:if test='<%= request.isUserInRole("admin") || request.isUserInRole("tutor")%>'>
                                                    <option value="5">Удалить</option>
                                                </c:if>
                                            </optgroup>
                                        </select>
                                    </td>
                                </tr>

                            </c:forEach>

                        </tbody>

                    </table>
                </form>

            </c:when><c:otherwise>
                <p>Список курсов пуст</p>
            </c:otherwise>
        </c:choose>

    </div>
    <br/>
    <%--<form id="signStudentsForm" action="SignStudents" style="display: none;">
        <input type="hidden" id="signStudentsInput" name="courseId"/>
    </form>
    <form id="signTutorsForm" action="SignTutors" style="display: none;">
        <input type="hidden" id="signTutorsInput" name="courseId"/>
    </form>--%>

    <%--<c:if test="${sessionScope.roles.admin || sessionScope.role.tutor}">--%>
    <c:if test='<%= request.isUserInRole("admin") || request.isUserInRole("tutor")%>'>
        <div id="box" class="rounded-top" name="addCourseDiv">
            <div id="rightnow" style="border: none; cursor: help;" onclick="toggleNewFormDiv()" class="rounded-top">
                <h3 class="reallynow rounded-top">
                    <span>Добавить курс</span>
                    <a class="add">Отобразить</a>
                    <br/>
                </h3>
            </div>

            <div id="newFormDiv" style="padding: 0px; margin: 0px; display: none;">
                <form id="form" action="AddCourseServlet" class="rounded-formcascade" name="newcourse" method="post">
                    <fieldset>
                        <legend>
                            <a name="addCourse">Новый курс</a>
                        </legend>
                        <label for="courseTitle">
                            Название курса :
                        </label>
                        <input name="courseTitle" id="courseTitle" type="text" tabindex="1" />
                        <br/>

                        <label for="direction">
                            Направление :
                        </label>
                        <select name="direction" id="directionSelect" tabindex="3" onchange="directionSelectChanged()">
                            <c:forEach var="direction" items="${directionList}">
                                <option value="${direction.id}">${direction.title}</option>
                            </c:forEach>
                            <option value="-1" onclick="newDirectionSelectClicked();">Новое направление...</option>
                        </select>

                        <br/>
                        <label for="newDirection">
                            Новое направление :
                        </label>
                        <input name="newDirection" align="left" disabled tabindex="4" value="Новое направление" id="newDirectionInput" type="text"/>

                        <label for="courseNumber">
                            Номер :
                        </label>
                        <input name="courseNumber" id="courseNumber" type="text" tabindex="2" style="width: 197px;" />
                        <span>(указывать необязательно)</span>
                        <br/>

                        <label for="attach">
                            Приложить файл
                        </label>
                        <input id="attachInput" align="left" type="button" value="Приложить файл" tabindex="5" style="width: 205px;" onclick="attachFile();"/>
                        <div id="attachDiv" style="display: none;">
                            <input type="file" align="left" name="attach" tabindex="5" />

                            <label for="attachTitle">
                                Название приложения
                            </label>
                            <input type="text" name="attachTitle" tabindex="6" />
                        </div>
                        <br/>

                        <label for="description">
                            Описание :
                        </label>
                        <textarea name="description" style="height: 50px;" tabindex="5" class="taWysiwyg" id="textAreaDescription" onmouseover="textAreaFocus()" onmouseout="textAreaBlur()" ></textarea>
                        <br/>
                        <a href="javascript:" class="goWysiwyg">форматировать текст</a>

                        <%-- <label> </label><a href="javascript:setup();">Форматировать текст</a> --%>
                        <br/>
                    </fieldset>
                    <div align="center">
                        <input id="button1" type="submit" tabindex="6" value="Добавить" />
                        <input id="button2" type="reset" tabindex="7" value="Очистить"/>
                    </div>
                </form>
            </div>
        </div>
    </c:if>

    <script type="text/javascript">
        function toggleNewFormDiv() {
            $('div#newFormDiv').slideToggle('slow', function(){window.location = '#addCourse'});
        }

    
        $(document).ready(function(){
            $("#liCourses").addClass("current");
            $('div#top-panel p').text('Дистанционные курсы в системе');

        <%--var defaultVal = 'Введите описание курса';
        $("#textAreaDescription").focus(function(){
            if(this.value == defaultVal){
                this.value = '';
            }
        }).blur(function(){
            if(this.value == ''){
                this.value = defaultVal;
            }
        });--%>

                try { //  datatable
                    doDatatable('courseTable')
        <%--var tableId = "courseTable";
        $('#'+tableId).dataTable( {
            // "sPaginationType": "full_numbers",

                    "oLanguage": {
                        // "sUrl": "datatable/dataTables.russian.txt"
                        // *
                        "sLengthMenu": "Показывать _MENU_ записей на странице",
                        "sZeroRecords": "Нет записей",
                        "sInfo": "Показано _START_ - _END_ записей из _TOTAL_",
                        "sInfoEmtpy": "Нет записей",
                        "sInfoFiltered": "(выбрано из _MAX_ записей)",
                        "sSearch": "Фильтр"
                        // */
                    }
                    , "bSort": false

                } );
                $('#'+tableId+'_wrapper').css("margin-top", "4px");
                $('#'+tableId+'_length').css("margin-left", "5px");
                $('#'+tableId+'_filter').css("margin-right", "10px");
                $('#'+tableId+'_info').css("margin-left", "4px");
                $('#'+tableId+'_paginate').css("margin-right", "10px");
                $('#'+tableId+'_paginate').css("margin-bottom", "4px");

                if($.browser.opera || $.browser.webkit) {
                    $('#'+tableId).css('width', '98%');
                }--%>
                        } catch (e) {}

                        // / datatable
                    });

        
    </script>
</body>
<%--</html>--%>

